﻿#region

using System.Collections.Generic;
using System.Linq;
using Lab.DataContext.DataContext;
using Lab.Server.Domain;

#endregion

namespace Lab.Server.Infrastructure {
    public class SkillRepository : Repository<Skill, skill> {
        public SkillRepository(IDataContext dataContext) : base(dataContext) {}

        protected override skill TranslateToDataObject(Skill domainObject) {
            return new skill { skill_description = domainObject.Description };
        }

        public skills_for_vacancy GetSkillForVacancy(Skill skill) {
            return new skills_for_vacancy { skill = GetSkillDataObject(skill) };
        }

        private skill GetSkillDataObject(Skill skill) {
            return DataContext.GetSkills().Single(_ => _.skill_id == skill.Id);
        }

        public skills_of_applicant GetSkillOfApplicant(Skill skill) {
            return new skills_of_applicant { skill = GetSkillDataObject(skill) };
        }

        public Skill TranslateToDomain(skill skill) {
            return new Skill { Id = skill.skill_id, Description = skill.skill_description };
        }

        public List<Skill> GetSkills() {
            return DataContext.GetSkills().ConvertAll(TranslateToDomain);
        }
    }
}